package com.hex.ds.hdrs.common.helper;

import com.hex.bigdata.hbda.domain.DictDetail;
import com.hex.bigdata.hbda.service.DictDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
public class DictHelper {

    @Autowired
    private DictDetailService service;
    private static DictDetailService dictDetailService;

    @PostConstruct
    public void init(){
        dictDetailService = service;
    }

    /**
     * 查询字典
     *
     * @param dictCode
     * @return
     */
    public static List<DictDetail> qryDictDetail(String dictCode) {
        return dictDetailService.findDictDetailByName(dictCode);
    }

    /**
     * 通过字典value 查询 相应 label
     * @param dictCode 字典码值
     * @param val  具体值
     * @return
     */
    public static String getDictLabel(String dictCode, String val) {
        DictDetail dictDetail = dictDetailService.findDictDetailByNameAndVal(dictCode, val);
        return dictDetail.getLabel();
    }
}
